FELIX-6327 - NoSuchElementException when services are removed #47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The tryInvokeBind method needs more safeguards around when the reference
that just got bound is detected that it got removed.
The previous code always assumed there was at least one other viable
reference to bind to. That causes the NoSuchElementException when
trying to find a fallback reference. Fixing that exposed another issue
with the previous code where the state of the DependencyManager is not
properly restored in two aspects:
Even when unbind is not invoked during tryInvokeBind the
currentRefPair would get set to null when it must remain set to the
previous value in cases where the invoke bind fails. A check is needed
to be sure to only clear the currentRefPair if unbind was successfully
invoked.
After invoking bind/unbind there is a check to see if the reference
is still viable (not deleted). This is where the reported problem
occurs when there is no alternative reference available and a
NoSuchElementException is thrown. Avoiding the NoSuchElementException
and returning from tryInvokeBind would leave the DependencyManager in a
state where it thinks there is still a binding thread doing work when
that thread is really done. Additional checks are needed to ensure we
always restore the binding thread state of the DepenencyManager on exit
of tryInvokeBind method.